From d395ae2bd3db4c92df1f9d9d89907e889672fa0c Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Thu, 12 Nov 2015 22:45:58 -0600 Subject: [PATCH] Add fields option to unicsv reader. Doc + test. --- testo.d/unicsv.test | 4 ++++ unicsv.cc | 18 +++++++++++++++--- xmldoc/formats/options/unicsv-fields.xml | 20 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 xmldoc/formats/options/unicsv-fields.xml diff --git a/testo.d/unicsv.test b/testo.d/unicsv.test index 5115002c4..610006e17 100644 --- a/testo.d/unicsv.test +++ b/testo.d/unicsv.test @@ -26,3 +26,7 @@ compare ${TMPDIR}/unicsv_encoding.csv ${REFERENCE}/unicsv_encoding.csv # verify fractional second read and writes. gpsbabel -i unicsv -f ${REFERENCE}/unicsv_subsec.csv -o unicsv -F ${TMPDIR}/unicsv_subsec.csv compare ${TMPDIR}/unicsv_subsec.csv ${REFERENCE}/unicsv_subsec.csv + +# Verify 'fields' option +gpsbabel -i unicsv,fields=lat+lon+description -f ${REFERENCE}/radius.csv -o csv -F ${TMPDIR}/unicsv_fields.out +compare ${REFERENCE}/radius.csv ${TMPDIR}/unicsv_fields.out diff --git a/unicsv.cc b/unicsv.cc index 72755c069..56a426f70 100644 --- a/unicsv.cc +++ b/unicsv.cc @@ -249,7 +249,13 @@ static route_head* unicsv_track, *unicsv_route; static char unicsv_outp_flags[(fld_terminator + 8) / 8]; static grid_type unicsv_grid_idx; static int unicsv_datum_idx; -static char* opt_datum, *opt_grid, *opt_utc, *opt_filename, *opt_format, *opt_prec; +static char* opt_datum; +static char* opt_grid; +static char* opt_utc; +static char* opt_filename; +static char* opt_format; +static char* opt_prec; +static char* opt_fields; static int unicsv_waypt_ct; static char unicsv_detect; static int llprec; @@ -279,6 +285,10 @@ static arglist_t unicsv_args[] = { "prec", &opt_prec, "Precision of numerical coordinates (no grid set)", "6", ARGTYPE_INT | ARGTYPE_HIDDEN, "0", "15" }, + { + "fields", &opt_fields, "Name and order of input fields, separated by '+'", + NULL, ARGTYPE_STRING, ARG_NOMINMAX + }, ARG_TERMINATOR }; @@ -594,8 +604,10 @@ unicsv_rd_init(const char* fname) unicsv_datum_idx = gt_lookup_datum_index(opt_datum, MYNAME); fin = gbfopen(fname, "rb", MYNAME); - - if ((c = gbfgetstr(fin))) { + if (opt_fields) { + QString fields = QString(opt_fields).replace("+", ","); + unicsv_fondle_header(fields); + } else if ((c = gbfgetstr(fin))) { unicsv_fondle_header(c); } else { unicsv_fieldsep = NULL; diff --git a/xmldoc/formats/options/unicsv-fields.xml b/xmldoc/formats/options/unicsv-fields.xml new file mode 100644 index 000000000..f54897ee2 --- /dev/null +++ b/xmldoc/formats/options/unicsv-fields.xml @@ -0,0 +1,20 @@ + +This option lets you specify the field names of your input file from +the command line instead of relying on the first line of your input +file describing the file. Field names are separated by a '+' character. +The list of field names is exactly that allowed in the first line of a +unicsv file without this option. + + + + Example for unicsv fields option to describe input file. + + For example ... + + gpsbabel -i unicsv,fields=lat+lon+description -f file.csv -o gpx -F file.gpx + + declares that file.csv has three fields, latitude, longitude, + and description, in that order. + + + -- 2.30.2